package com.cs.study.homework._0302;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

public class Demo5 {
    public static void main(String[] args) throws IOException {
        FileInputStream in = null;
        FileOutputStream out = null;
        int oddCount = 0;
        int evenCount = 0;
        try {
            int readData;
            in = new FileInputStream("E:\\a\\test.txt");
            while ((readData = in.read()) != -1) {
                if (readData % 2 == 0) {
                    evenCount++;
                } else if (readData % 2 != 0) {
                    oddCount++;
                }
            }
            out = new FileOutputStream("E:\\a\\test.txt");
            out.write("\r\n".getBytes());
            out.write(("偶数个数:" + evenCount).getBytes());
            out.write("\r\n".getBytes());
            out.write(("奇数个数:" + oddCount).getBytes());
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        System.out.println("evenCount = " + evenCount);
        System.out.println("oddCount = " + oddCount);

    }
}
